<?php $this->load->view('header');?>

<body class="childrenBody">
    <blockquote class="layui-elem-quote news_search">
		<div>
			<div class="layui-inline">
				<a class="layui-btn layui-btn-custom Add_btn"><i class="layui-icon">&#xe654;</i> 类型</a>
			</div>
		</div>
		
	</blockquote>

	<!-- 视图 -->
	<div class="layui-form news_list">
		<form class="layui-form">
			<table class="layui-table" lay-even="" lay-skin="line">
			    <thead>
				<tr>
					<th>类型名称</th>
					<th>操作</th>
				</tr> 
			    </thead>
				<tbody class="goods_content" id="view">
					<?php foreach ($type_list as $item):?>
					<tr>
					  <td><?=$item['name']?></td>
					  <td>
					    <a class="layui-btn layui-btn-warm layui-btn-mini" onclick="_edit(<?=$item['id']?>);" title="编辑">
					      <i class="layui-icon">&#xe642;</i>编辑
					    </a>
					    <a class="layui-btn layui-btn-danger layui-btn-mini" onclick="_delete(<?=$item['id']?>);" title="删除">
					      <i class="layui-icon">&#xe640;</i>删除
					    </a>
					  </td>
					</tr>
					<?php endforeach;?>
				</tbody>
			</table>
		</form>
	</div>

	<script type="text/javascript">
	layui.config({
		version: true
	}).use(['jquery','layer', 'laytpl', 'form', 'element'],function(){
		var layer = parent.layer === undefined ? layui.layer : parent.layer,
			laytpl = layui.laytpl,
			form = layui.form,
			element = layui.element,
			$ = layui.jquery;


			//添加分类
			$('.Add_btn').click(function() 
			{
				layer.prompt({title: '请填写类型名称', formType: 3}, function(text, index)
				{
				    $.post('admin.php/Article/add_type', {type_name: text}, function(res) 
				    {
				    	if (res.status == 200) {
				    		layer.msg(res.message, {icon: 1});
				    		layer.close(index);
				    		location.reload();
				    	}else{
				    		layer.msg(res.message, {icon: 5});
				    	}
				    	
				    },'JSON');

				});

			});

	});


	//编辑
	function _edit(id)
	{
		layer.prompt({title: '请填写类型名称', formType: 3}, function(text, index)
		{
		    $.post('admin.php/Article/add_type', {type_name: text,type_id:id}, function(res) 
		    {
		    	if (res.status == 200) {
		    		layer.msg(res.message, {icon: 1});
		    		layer.close(index);
		    		location.reload();
		    	}else{
		    		layer.msg(res.message, {icon: 5});
		    	}
		    	
		    },'JSON');

		});

	}



	//删除
	function _delete(id)
	{
		layer.confirm('确定删除选中的信息？',{icon:3, title:'提示信息'},function(index){
			$.get('admin.php/Article/delete_type',{type_id:id}, function(res) {
				if (res.status == 200) {
					layer.msg(res.message, {icon:1});
					location.reload();
				}
				else
				{
					layer.msg(res.message, {icon:2});
				}
			},"json");
		});

	}


	</script>

</body>
</html>